package com.itboye.mengwu.app.logincontroller;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;

import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.DebugLog;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.app.MainApplication;
import com.itboye.mengwu.app.ui.mymeng.MyTieZiActivity;
import com.itboye.mengwu.main.WoMengFragment;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.MsgConstant;
import com.umeng.message.PushAgent;
import com.umeng.message.UmengRegistrar;

/**
 * 登录相关控制类--状态模式</br></br>
 * 
 * 登录成功后调用setLoginState(new LoginedState());</br></br> 退出登录后调用setLoginState(new
 * UnLoginState());</br></br> 进入主Activity前一定要设置一次，要么登录要么未登录</br></br>
 * 
 * @author Mr.w
 * 
 */
public class LoginController {

	private static ILoginState loginState = new UnLoginState();

	public static void setLoginState(ILoginState loginState) {

		LoginController.loginState = loginState;
		if (loginState instanceof UnLoginState) {
			DebugLog.v("bytag", "未登录。。。");
		} else if (loginState instanceof LoginedState) {
			DebugLog.v("bytag", "已登录。。。");
			PushAgent mPushAgent = PushAgent
					.getInstance(MainApplication.context);
			// mPushAgent.setPushIntentServiceClass(MyPushIntentService.class);
			mPushAgent
					.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_ENABLE);
			mPushAgent.onAppStart();
			// 开启推送并设置注册的回调处理
			if (!mPushAgent.isEnabled()) {
				mPushAgent.enable(new IUmengRegisterCallback() {

					@Override
					public void onRegistered(String registrationId) {
						// onRegistered方法的参数registrationId即是device_token

						setExclusiveAlias(registrationId);
					}
				});
			}

			String device_token = UmengRegistrar
					.getRegistrationId(MainApplication.context);
			if (!TextUtils.isEmpty(device_token)) {
				setExclusiveAlias(device_token);
			}
		}
	}

	private static void setExclusiveAlias(String registrationId) {
		String uid = (String) SPUtils.get(MainApplication.context, null,
				SpPublicParams.UID, "");
		PushAgent mPushAgent = PushAgent.getInstance(MainApplication.context);
		mPushAgent.setExclusiveAlias(uid, "mengwu");
		DebugLog.v("bytag", "setExclusiveAlias   token:", registrationId,
				" alian:", uid, "  type:", "mengwu");

	}

	public static void testClick(Activity act, Object data) {
		loginState.test(act, data);
	}

	public static void queryMyMessae(Activity act, Object data) {
		loginState.goToMyMessage(act, data);
	}

	/**
	 * 
	 * @param 个人设置
	 * @param data
	 */
	public static void onPersonalsettingClick(Activity act, Object data) {
		loginState.goToMyMessage(act, data);
	}

	/**
	 * 
	 * @param 换购商城
	 * @param data
	 */
	public static void onHuan(Activity act, String data, String data2) {
		loginState.getHuan(act, data, data2);
	}

	/***
	 * 我的帖子
	 */
	public static void onMyTieZi(Activity act, Object data) {
		loginState.getMyTieZi(act, data);
	}

	/***
	 * 
	 * @param 我的售后
	 * @param data
	 */
	public static void onOrder(Activity act, Object data) {
		loginState.getMyOrder(act, data);
	}

	/**
	 * 
	 * @param 待评价
	 * @param data
	 */
	public static void onPingjia(Activity act, Object data) {
		loginState.getPingjia(act, data);
	}

	/**
	 * @param 待收货
	 * @param data
	 */
	public static void onShouHuo(Activity act, Object data) {
		loginState.getShouHuo(act, data);
	}

	/**
	 * @param 待付款
	 * @param data
	 */
	public static void onFukuan(Activity act, Object data) {
		loginState.getFukuan(act, data);
	}

	/**
	 * @param 地址管理
	 * @param data
	 */
	public static void onAddress(Activity act, Object data) {
		loginState.getAddress(act, data);
	}

	/**
	 * @param 零钱
	 * @param data
	 */
	public static void onSmall(Activity act, Object data) {
		loginState.getSmol(act, data);
	}

	/**
	 * @param 红包
	 * @param data
	 */
	public static void onRed(Activity act, Object data) {
		loginState.getRed(act, data);
	}

	/**
	 * @param 萌币
	 * @param data
	 */
	public static void onMengBi(Activity act, String data, String data2) {
		loginState.getMengBi(act, data, data2);
	}

	/**
	 * 添加收藏商品
	 * 
	 * @param act
	 * @param data
	 */
	public static void collection(Activity act, Object data) {
		loginState.collection(act, data);
	}

	/***
	 * 查看收藏商品
	 * 
	 * @param activity
	 * @param obj
	 */
	public static void queryMyCollection(Activity activity, Object obj) {
		loginState.queryMyCollection(activity, obj);
	}
//	public static void queryMyCollection(Activity activity, Object obj) {
//		loginState.queryMyCollection(activity, obj);
//	}

	public static void Mengmengche(Activity act, Object data) {
		loginState.queryShopCart(act, data);
	}

	/***
	 * 圈消息
	 */
	public static void QuanMessge(Activity act, Object data) {
		loginState.QuanMessgeDate(act, data);
	}

	/**
	 * 个人空间
	 * 
	 * @param act
	 * @param data
	 */
	public static void gotoGerenKongjian(Activity act, Object data) {
		loginState.gerenKongJian(act, data);
	}

	/**
	 * 萌时光
	 * 
	 * @param act
	 * @param data
	 */
	public static void MengTime(Activity act, Object data) {
		loginState.mengTime(act, data);
	}

	public static void guanzhu(Activity act, Object data) {
		loginState.guanzhu(act, data);
	}

	/**
	 * 我萌登陆为题
	 * 
	 * @param act
	 * @param data
	 */
	public static void onButton(Activity act, Object data) {
		loginState.onButton(act, data);
	}

	/**
	 * 我的评价
	 * 
	 * @param act
	 * @param data
	 */

	public static void MePingjia(Activity act, Object data) {
		loginState.MePingjia(act, data);
	}

	public static void woDeDongTai(Activity act, Object data) {
		loginState.woDeDongTai(act, data);
	}

	public static void onDaiJinQuan(Activity act, Object data) {

		loginState.getDaiJinQuan(act, data);

	}

	public static void onlickShouCang(Context myTieZiActivity, Object object) {
		// TODO Auto-generated method stub
		loginState.onlickShouCang((Activity) myTieZiActivity, object);
	}

	/**
	 * 邀请有奖
	 * 
	 * @param act
	 * @param data
	 */
	public static void InvitationPrize(Activity act, String data, String data2) {
		// TODO Auto-generated method stub
		loginState.InvitationPrize(act, data, data2);
	}

	/**
	 * 帮助
	 * 
	 * @param act
	 * @param data
	 */
	public static void Help(Activity act, String data, String data2) {
		// TODO Auto-generated method stub
		loginState.Help(act, data, data2);
	}

	public static void vip(Activity act, String data, String data2) {
		// TODO Auto-generated method stub
		loginState.vip(act, data, data2);
	}
	public static void MyAllOrder(Activity act, Object data) {
		// TODO Auto-generated method stub
		loginState.MyAllOrder(act, data);
	}
	// public static void guanzhuOther(Context myTieZiActivity, Object object) {
	// // TODO Auto-generated method stub
	// loginState.onlickShouCang((Activity) myTieZiActivity, object);
	// }
}
